import * as THREE from "three";

//https://www.solarsystemscope.com/textures/

export default function () {
    const a = 6378.1; // 赤道半径
    const b = 6356.8;
    const selfSpeed = 0.001227; //实际速度除以1000

    let earth: THREE.Mesh;

  function drawEarth(scene: THREE.Scene) {
    const loader = new THREE.TextureLoader();
    loader.load("./8k_earth_daymap.jpg", (texture) => {
      const geometry = new THREE.SphereGeometry(a, 128, 128);
      const material = new THREE.MeshBasicMaterial({
        map: texture,
      });
      earth = new THREE.Mesh(geometry, material);
      earth.scale.set(1, 1, b/a);
      scene.add(earth);
    },()=>{

    },(err)=>{
        console.log("error",err);
    });
  }

  function earthRender(){
    if(earth!=null) {
        earth.rotation.y += selfSpeed;
    }
  }

  return { drawEarth,earthRender };
}
